package com.example.demo.controller;

import com.example.demo.entity.Sys_role;
import com.example.demo.service.Sys_roleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SysController {
    @Autowired
    Sys_roleService sys_roleService;
    @GetMapping ("/saveRole")
    public String savaSys_role(){
        Sys_role sys_role = new Sys_role();
        sys_role.setName("张三");
        sys_role.setDescription("普通职员");
        sys_role.setCreate_time(20240331);
        sys_role.setCreate_by("employee");
        sys_role.setUpdate_time(20240331);
        sys_role.setUpdate_by("employee");
        sys_role.setDel_flag(1);
        int result = sys_roleService.saveSys_role(sys_role);
        if (result>0){
            return "添加员工成功！";
        }else {
            return "添加员工失败！";
        }
    }

    @GetMapping("/getAll")
    public List<Sys_role> getAllSys_role(){
        return sys_roleService.getAllSys_role();
    }

    @GetMapping("/getById/{id}")
    public Sys_role getSys_roleById(@PathVariable Integer id){
        return sys_roleService.getSys_roleById(id);
    }

    @GetMapping("/updateRole/{id}")
    public String updateSys_role(@PathVariable Integer id){
        int result = sys_roleService.updateSys_role(id);
        if (result > 0) {
            return "更新员工信息成功！";
        } else {
            return "更新员工信息失败！";
        }
    }


    @GetMapping("/deleteRole/{id}")
    public String deleteSys_roleById(@PathVariable Integer id){
        int result = sys_roleService.deleteSys_roleById(id);
        if (result > 0) {
            return "删除员工成功！";
        } else {
            return "删除员工失败！";
        }
    }

}
